<?php

namespace models\DAO;

use models\Exception\DAO\ModelDriverException;
use models\Exception\DAO\ModelException;
use models\Exception\DAO\ModelReflectionException;
use models\Exception\DAO\ModelSqlException;


/**
 * @SWG\Swagger(
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductactivitySingleData",
 *          required={"errno", "errmsg", "data"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", type="object", ref="#/definitions/alibabaproductactivitySingleObj")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductactivitySingleObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/alibabaproductactivitySingle")
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductactivityListData",
 *          required={"errno", "errmsg", "result"},
 *          @SWG\Property(property="errno", type="integer", format="int32", description="编码"),
 *          @SWG\Property(property="errmsg", type="string", format="string", description="错误提示信息"),
 *          @SWG\Property(property="result", ref="#/definitions/alibabaproductactivityListObj"),
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductactivityListObj",
 *          @SWG\Property(property="data", type="object", ref="#/definitions/alibabaproductactivityData"),
 *          @SWG\Property(property="meta", ref="#/definitions/meta")
 *     ),
 *     @SWG\Definition(
 *          type="array",
 *          definition="alibabaproductactivityData",
 *          @SWG\Items(
 *              title="data", ref="#/definitions/alibabaproductactivitySingle"
 *          )
 *     ),
 *     @SWG\Definition(
 *          type="object",
 *          definition="alibabaproductactivitySingle",
 *          @SWG\Property(property="product_id", type="string", format="string",  description="1688商品编号"),
 *          @SWG\Property(property="activity_id", type="integer", format="int32",  description="活动编号"),
 *          @SWG\Property(property="begin_quantity", type="integer", format="int32",  description="活动起批量"),
 *          @SWG\Property(property="stock", type="integer", format="int32",  description="活动总库存，为0时使用offer原库存"),
 *          @SWG\Property(property="person_limit_count", type="integer", format="int32",  description="商品本身限购数，非活动价可购买数；-1表示不限，0表示可购买数为0；3个*LimitCount字段都等于-1时，表示没有任何限购"),
 *          @SWG\Property(property="promotion_limit_count", type="integer", format="int32",  description="限购数，等于0且personLimitCount>0时，可以以原价下单，但不能以活动价下单；-1表示不限数量；3个*LimitCount字段都等于-1时，表示没有任何限购"),
 *          @SWG\Property(property="activity_limit_count", type="integer", format="int32",  description="活动限购数；该场内活动商品限购数，-1表示不限购；0表示不可购买该场活动所有商品；3个*LimitCount字段都等于-1时，表示没有任何限购"),
 *          @SWG\Property(property="free_postage_start_time", type="string", format="string",  description="活动限时包邮开始时间；null 表示不限时"),
 *          @SWG\Property(property="free_postage_end_time", type="string", format="string",  description="活动限时包邮结束时间；null 表示不限时"),
 *          @SWG\Property(property="exclude_area_list", type="string", format="string",  description="免包邮地区，与活动包邮配合使用"),
 *          @SWG\Property(property="range_price", type="string", format="string",  description="如果offer是范围报价，且价格优惠是折扣的情况，返回折扣计算后的价格范围;优先取该字段，该字段为空时，表示分sku报价，取promotionItemList"),
 *          @SWG\Property(property="promotion_item_list", type="string", format="string",  description="优惠结果，根据优惠方式（PromotionInfo），结合offer的原价信息，计算出优惠结果：每个sku或者每个区间价的促销价，折扣率"),
 *          @SWG\Property(property="sku_stock_list", type="string", format="string",  description="sku维度的库存结果"),
 *          @SWG\Property(property="intro_order_flow", type="string", format="string",  description="这里平台会计算一个推荐使用的下单flow，可以用这个flow值调用下单接口"),
 *     )
 * )
 */
class AlibabaproductactivityModel extends BaseModel{
    /**
     * 1688商品编号
     */
    public $product_id = null;

    /**
     * 活动编号
     */
    public $activity_id = null;

    /**
     * 活动起批量
     */
    public $begin_quantity = null;

    /**
     * 活动总库存，为0时使用offer原库存
     */
    public $stock = null;

    /**
     * 商品本身限购数，非活动价可购买数；-1表示不限，0表示可购买数为0；3个*LimitCount字段都等于-1时，表示没有任何限购
     */
    public $person_limit_count = null;

    /**
     * 限购数，等于0且personLimitCount>0时，可以以原价下单，但不能以活动价下单；-1表示不限数量；3个*LimitCount字段都等于-1时，表示没有任何限购
     */
    public $promotion_limit_count = null;

    /**
     * 活动限购数；该场内活动商品限购数，-1表示不限购；0表示不可购买该场活动所有商品；3个*LimitCount字段都等于-1时，表示没有任何限购
     */
    public $activity_limit_count = null;

    /**
     * 活动限时包邮开始时间；null 表示不限时
     */
    public $free_postage_start_time = "";

    /**
     * 活动限时包邮结束时间；null 表示不限时
     */
    public $free_postage_end_time = "";

    /**
     * 免包邮地区，与活动包邮配合使用
     */
    public $exclude_area_list = "";

    /**
     * 如果offer是范围报价，且价格优惠是折扣的情况，返回折扣计算后的价格范围;优先取该字段，该字段为空时，表示分sku报价，取promotionItemList
     */
    public $range_price = "";

    /**
     * 优惠结果，根据优惠方式（PromotionInfo），结合offer的原价信息，计算出优惠结果：每个sku或者每个区间价的促销价，折扣率
     */
    public $promotion_item_list = "";

    /**
     * sku维度的库存结果
     */
    public $sku_stock_list = "";

    /**
     * 这里平台会计算一个推荐使用的下单flow，可以用这个flow值调用下单接口
     */
    public $intro_order_flow = null;
    /**
     * DAO对象
     */
    public $obj = '';

    /**
     * DAO对象数组
     */
    public $data = [];

    /**
     * 翻页对象
     */
    public $meta = null;

    /**
     * 当前页
     */
    public $page = 1;

    /**
     * 每页显示条数
     */
    public $page_size = 10;

    /**
     * 主键数组
     */
    public $primary_key_arr = ["product_id", "activity_id"];

    /**
     * 自增字段数组
     */
    public $auto_increment_key_arr = [];

    /**
     * 唯一字段
     */
    public $unique_key_arr = '';

    /**
     * 单例实例
     */
    static public $instance = null;

    /**
     * @return AlibabaproductactivityModel|null
     * @throws ModelSqlException
     */
    static public function getInstance() {
        if(is_null(self::$instance)){
            self::$instance = new self();
        }
        return self::$instance;
    }

    /**
     * AlibabaproductactivityModel constructor.
     * @throws ModelSqlException
     */
    public function __construct() {
        parent::__construct(str_replace("Model", "", substr(get_class($this), strrpos(get_class($this), "\\")+1)));
        $this->meta = new \stdClass();
    }

    /**
     * @throws ModelException
     */
    public function __clone() {
        throw new ModelException(
            str_replace('%s', get_class($this), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE), ModelException::INSTANCE_NOT_ALLOW_TO_CLONE_NO);
    }

    public function __destruct() {
        self::$instance = null;
    }

    /**
     * set属性
     *
     * __set.
     * @param string $name 参数名
     * @param string $value 参数值
     * @return $this
     */
    public function __set($name = "", $value = "") {
        $this->$name = $value;
        return $this;
    }

    /**
     * get属性
     *
     * __get.
     * @param string $name 参数名
     * @return mixed
     */
    public function __get($name = "") {
        return  $this->$name ;
    }

    /**
     * 创建alibabaproductactivityModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function insert() {
        return $this->insertRecord();
    }

    /**
     * 编辑alibabaproductactivityModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function update() {
        return $this->updateRecord();
    }

    /**
     * 删除alibabaproductactivityModel，需先指定主键
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     * @throws ModelException
     */
    public function delete() {
        return $this->deleteRecord();
    }

    /**
     * 根据主键查询alibabaproductactivityModel，获取单条记录
     *
     * find.
     * @param int $primary_key 主键编号
     * @return $this
     * @throws ModelException
     * @throws ModelReflectionException
     */
    public function find($primary_key = 0) {
        $result = $this->findByPrimaryKey($primary_key);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询alibabaproductactivityModel，获取多条记录
     *
     * findOneBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findOneBy($condition = []) {
        $result = $this->findRecordBy($condition);

        $this->setModelProperty($result);

        return $this;
    }

    /**
     * 根据条件数组查询alibabaproductactivityModel，获取多条记录
     *
     * findBy.
     * @param array $condition 查询条件
     * @return $this
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelReflectionException
     * @throws ModelSqlException
     */
    public function findBy($condition = []) {
        $count = $this->getCount($condition);
        $total = $count->fetchColumn();

        $this->data = [];
        $alib_obj = $this->findRecordBy($condition, $this->page, $this->page_size);

        $this->genMeta($total);
        $this->setModelProperty($alib_obj, true);

        return $this;
    }

    /**
     * 批量插入alibabaproductactivityModel
     *
     * @return mixed
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchInsert() {
        return $this->batchInsertRecord();
    }

    /**
     * 批量删除alibabaproductactivityModel
     *
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function batchDelete() {
        $this->batchDeleteRecord();
    }

    /**
     * 生成批量生成update的sql
     *
     * @return bool|string
     * @throws ModelDriverException
     * @throws ModelException
     * @throws ModelSqlException
     */
    public function genBatchUpdateSql() {
        return $this->_genBatchUpdateSql();
    }

}
